# -*- coding: utf-8 -*-
# @Time    : 2024/8/29 0:28
# @Author  : Alvin
# @File    : points_log.py

from sqlalchemy import Column, Integer, ForeignKey, String
from sqlalchemy.orm import Relationship

from app.models.base import Base, db


class PointsLog(Base):
    __tablename__ = 'points_log'
    users = Relationship('User')
    log_id = Column(Integer, primary_key=True)
    user_id = Column(Integer, ForeignKey('users.id'))
    points_before = Column(Integer)
    points_changed = Column(Integer)
    points_after = Column(Integer)
    reason = Column(String(255))
    # log_time = Column(DateTime, default=datetime.utcnow)


    @staticmethod
    def insert_points_log(user_id, points_before, points_changed, points_after, reason):
        with db.auto_commit():
            points_log = PointsLog()
            points_log.user_id = user_id
            points_log.points_before = points_before
            points_log.points_changed = points_changed
            points_log.points_after = points_after
            points_log.reason = reason
            db.session.add(points_log)
